Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Native ETH in v1 #1354

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Support Native ETH in v1 #1354

wants to merge 22 commits into from

Conversation

alistair-singh
Copy link
Contributor

@alistair-singh alistair-singh commented Dec 12, 2024

Changes

  1. Use the 0x0000000000000000000000000000000000000000 token address as Native ETH.
  2. When sendToken is called with the 0x00.. an amount of msg.value is locked in asset hub agent.
  3. To avoid clashing with fees/rewards and locked funds, fees/rewards are collected and dispensed from the Gateway Proxy account.
  4. The existing funds in the agents will be migrated on upgrade.
  5. Scripts which mentions FundAgent are now called FundGateway

Related polkadot-sdk: paritytech/polkadot-sdk#6855

TODO

  • Fix tests
  • Add tests for the Eth asserting msg.value.
  • Migrate agent funds to gateway proxy on upgrade

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 87.80488% with 5 lines in your changes missing coverage. Please review.

Project coverage is 76.58%. Comparing base (24b9d31) to head (89b9e09).
Report is 158 commits behind head on main.

Files with missing lines Patch % Lines
contracts/src/Assets.sol 84.21% 3 Missing ⚠️
contracts/src/upgrades/Gateway202410.sol 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1354      +/-   ##
==========================================
- Coverage   77.83%   76.58%   -1.25%     
==========================================
  Files          14       17       +3     
  Lines         415      739     +324     
  Branches       76      110      +34     
==========================================
+ Hits          323      566     +243     
- Misses         75      162      +87     
+ Partials       17       11       -6     
Flag Coverage Δ
solidity 76.58% <87.80%> (-1.25%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alistair-singh alistair-singh marked this pull request as ready for review December 17, 2024 23:52
Comment on lines 542 to 545
// Reimburse excess fee payment
if (msg.value > fee) {
payable(msg.sender).safeNativeTransfer(msg.value - fee);
if (msg.value > totalEther) {
payable(msg.sender).safeNativeTransfer(msg.value - totalEther);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this refund process still required since Gateway now is the vault of Ether? I'd suggest to remove it.

Or for security do we need to add some reentrantlock on outbound calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to port the functionality across as is. I changed the code to consider dust like we do in fees so that we do not transfer if the amount is too low. But I think it is good to refund the customer incase of any error in the input, we will not lock and hold more funds than we mint on the other side of the bridge.

Copy link
Contributor

@yrong yrong Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alistair-singh I added a PR #1356 with tests to demonstrate the reentrancy behavior through the refund process.

Adding the ReentrancyGuard did enhance the security somehow. On the other hand, it will also cost a bit more gas, and it seems our bridge can't be exploited in this way. So I'm still not sure if it's necessary.

Please let me know what you think.

Copy link
Contributor Author

@alistair-singh alistair-singh Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! How is ReentracyGuard different from the nonentrancy keyword in solidity 0.28 that we use in Contracts v2?

Copy link
Contributor

@yrong yrong Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contracts/src/Types.sol Outdated Show resolved Hide resolved
contracts/src/GatewayProxy.sol Outdated Show resolved Hide resolved
@alistair-singh
Copy link
Contributor Author

@vgeddes we have a Command called TransferNativeFromAgent which is a management-style command, issuable from bridgehub only, that can empty an agent account of ETH. We would need to add a similar command TransferNativeFromGateway to do the same thing for the Gateway. We should also maybe disable TransferNativeFromAgent so that there is no way to remove ETH from an agent other than an Unlock command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants